package xml.uidElements;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import xml.others.UIDException;
import xml.uidElements.entry.AbstractDataItem;
import xml.uidElements.entry.AbstractStructure;
import xml.uidElements.entry.EnumeratedData;
import xml.uidElements.entry.ORDataEntry;
import xml.uidElements.entry.SubState;
import xml.uidElements.entry.XORDataEntry;
import xml.uidElements.output.AbstractOutputDataItem;
import xml.uidElements.output.AbstractOutputStructure;

public class UID {

	private String name;
	private String id;
	private List<PreCondition> listPreConditions;
	private List<PosCondition> listPosConditions;
	private InitialState initialState;
	private Vector<State> setStates;
	private List<TextualNote> listTextualNotes;
	private Vector<UIDCall> setUIDCalls;

	public UID(String idUID, String name) {
		this.name = name;
		this.id = idUID;
		initialState = null;
		this.setStates = new Vector<State>();

		// this.setTransitions = new Vector<Transition> ();
		this.listPreConditions = new ArrayList<PreCondition>();
		this.listPosConditions = new ArrayList<PosCondition>();
		this.listTextualNotes = new ArrayList<TextualNote>();
		
		this.setUIDCalls = new Vector<UIDCall>();

	}

	public String getName() {
		return name;
	}

	public String getId() {
		return id;
	}

	public void insertInitialState(String idInitialState) {
		if (this.initialState != null)
			throw new UIDException(UIDException.EXISTING_STATE,
					"There is already a initial state");
		else {
			for (int i = 0; i < this.setStates.size(); i++) {
				State state = this.setStates.elementAt(i);
				if (state.getId().equals(idInitialState)) {
					throw new UIDException(UIDException.EXISTING_STATE,
							"There is already a state with this id");
				}
			}
		}
		this.initialState = new InitialState(idInitialState);

	}

	public void insertState(String idState) {

		if (this.initialState != null
				&& this.initialState.getId().equals(idState))
			throw new UIDException(UIDException.EXISTING_STATE,
					"There is already a state with this id");
		else {

			for (int i = 0; i < this.setStates.size(); i++) {
				AbstractState state = this.setStates.elementAt(i);
				if (state.getId().equals(idState)) {
					throw new UIDException(UIDException.EXISTING_STATE,
							"There is already a state with this id");
				}
			}
			State state = new State(idState);
			this.setStates.add(state);
		}

	}

	public void insertUIDCall(String idUIDCall, String name) {
		for (int i = 0; i < this.setUIDCalls.size(); i++) {
			UIDCall UC = this.setUIDCalls.elementAt(i);
			if (UC.getId().equals(idUIDCall)) {
				throw new UIDException(UIDException.EXISTING_UID_CALL,
				"There is already a UID call with this id");
				}
			}
		UIDCall UC = new UIDCall(idUIDCall, name);
		this.setUIDCalls.add(UC);
	}

	public void insertInputDataItem(String idState, AbstractDataItem dataItem) {

		AbstractState state = returnState(idState);
		state.insertInputDataItem(dataItem);

	}

	public void insertInputStructure(String idState, AbstractStructure structure) {
		AbstractState state = returnState(idState);
		state.insertInputStructure(structure);

	}

	private State returnState(String idState) {

		if (this.initialState != null && initialState.getId().equals(idState))
			return initialState;

		for (int i = 0; i < this.setStates.size(); i++) {
			State state = this.setStates.elementAt(i);
			if (state.getId().equals(idState))
				return state;

		}
		throw new UIDException(UIDException.NOT_EXISTING_STATE,
				"There is no state with this id");
	}

	public void insertPreCondition(PreCondition preCondition) {
		this.listPreConditions.add(preCondition);

	}

	public void insertPosCondition(PosCondition posCondition) {
		this.listPosConditions.add(posCondition);

	}

	public void insertTextualNote(TextualNote textualNote) {
		this.listTextualNotes.add(textualNote);

	}

	public void insertOutputDataItem(String idState,
			AbstractOutputDataItem dataItem) {

		AbstractState state = returnState(idState);
		state.insertOutputDataItem(dataItem);

	}

	public void insertOutputStructure(String idState,
			AbstractOutputStructure structure) {
		AbstractState state = returnState(idState);
		state.insertOutputStructure(structure);

	}

	public void insertInputEnumeratedData(String idState,
			EnumeratedData enumeratedData) {
		AbstractState state = returnState(idState);
		state.insertInputEnumeratedData(enumeratedData);

	}

	public void insertInputORDataEntry(String idState, ORDataEntry orDataEntry) {
		AbstractState state = returnState(idState);
		state.insertInputORDataEntry(orDataEntry);

	}

	public void insertInputXORDataEntry(String idState,
			XORDataEntry xorDataEntry) {
		AbstractState state = returnState(idState);
		state.insertInputXORDataEntry(xorDataEntry);

	}

	public void insertSubState(String idState, SubState subState) {
		State state = returnState(idState);
		state.insertSubState(subState);

	}

	public void insertOutputDataItemInSubState(String idState,
			String idSubState, AbstractOutputDataItem dataItem) {
		State state = returnState(idState);
		state.insertOutputDataItemInSubState(idSubState, dataItem);

	}

	public void insertInputDataItemInSubState(String idState,
			String idSubState, AbstractDataItem dataItem) {

		State state = returnState(idState);
		state.insertInputDataItemInSubState(idSubState, dataItem);

	}

	public void insertInputEnumeratedDataInSubState(String idState,
			String idSubState, EnumeratedData enumeratedData) {
		State state = returnState(idState);
		state.insertInputEnumeratedDataInSubState(idSubState, enumeratedData);

	}

	public void insertInputXORDataEntryInSubState(String idState,
			String idSubState, XORDataEntry xorDataEntry) {

		State state = returnState(idState);
		state.insertInputXORDataEntryInSubState(idSubState, xorDataEntry);

	}

	public void insertInputORDataEntryInSubState(String idState,
			String idSubState, ORDataEntry orDataEntry) {

		State state = returnState(idState);
		state.insertInputORDataEntryInSubState(idSubState, orDataEntry);

	}

	public void insertInputStructureInSubState(String idState,
			String idSubState, AbstractStructure structure) {

		State state = returnState(idState);
		state.insertInputStructureInSubState(idSubState, structure);

	}

	public void insertOutputStructureInSubState(String idState,
			String idSubState, AbstractOutputStructure structure) {

		State state = returnState(idState);
		state.insertOutputStructureInSubState(idSubState, structure);

	}

	public void insertText(String idState, Text text) {
		State state = returnState(idState);
		state.insertText(text);

	}

	public void insertTextInSubState(String idState, String idSubState,
			Text text) {
		State state = returnState(idState);
		state.insertTextInSubState(idSubState, text);

	}

	public void insertTransitionFromStateToState(String idSourceState,
			String idTargetState, String idTransition, String condition,
			String option) {

		AbstractState sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertOutgoingTransition(transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");
	}

	public void insertTransitionFromSubStateToState(String idSourceState,
			String idSourceSubState, String idTargetState, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromSubState(idSourceSubState,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromDataItemToState(String idSourceState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromStructureToState(String idSourceState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromDataItemInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromStructureInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition No Returnable
	public void insertTransitionNoReturnableFromStateToState(
			String idSourceState, String idTargetState, String idTransition,
			String condition, String option) {

		AbstractState sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertOutgoingTransition(transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");
	}

	public void insertTransitionNoReturnableFromSubStateToState(
			String idSourceState, String idSourceSubState,
			String idTargetState, String idTransition, String condition,
			String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSubState(idSourceSubState,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromDataItemToState(
			String idSourceState, String idSourceDataItem,
			String idTargetState, String idTransition, String condition,
			String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromStructureToState(
			String idSourceState, String idSourceStructure,
			String idTargetState, String idTransition, String condition,
			String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromDataItemInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromStructureInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			Transition transition = new Transition(idTransition, targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition from Set
	public void insertTransitionFromSetDataItemToState(String idSourceState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetStructureToState(String idSourceState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetDataItemInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetStructureInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition No Returnable from Set
	public void insertTransitionNoReturnableFromSetDataItemToState(
			String idSourceState, String idSourceDataItem,
			String idTargetState, String idTransition, String condition,
			String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetStructureToState(
			String idSourceState, String idSourceStructure,
			String idTargetState, String idTransition, String condition,
			String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetDataItemInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetState, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetStructureInSubStateToState(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetState,
			String idTransition, String condition, String option, int number) {

		State sourceState = returnState(idSourceState);
		AbstractState targetState = returnState(idTargetState);

		if (sourceState != null && targetState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					targetState);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// to UID
	// to UID
	// to UID
	// to UID
	// to UID
	// to UID
	// to UID
	// to UID
	// to UID
	public void insertTransitionFromStateToUIDCall(String idSourceState,
			String idTargetUIDCall, String idTransition, String condition,
			String option) {

		AbstractState sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertOutgoingTransition(transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");
	}

	public void insertTransitionFromSubStateToUIDCall(String idSourceState,
			String idSourceSubState, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromSubState(idSourceSubState,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromDataItemToUIDCall(String idSourceState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromStructureToUIDCall(String idSourceState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromDataItemInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromStructureInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			sourceState.insertTransitionFromStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition No Returnable
	public void insertTransitionNoReturnableFromStateToUIDCall(
			String idSourceState, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		AbstractState sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertOutgoingTransition(transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");
	}

	public void insertTransitionNoReturnableFromSubStateToUIDCall(
			String idSourceState, String idSourceSubState, String idTargetUIDCall,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSubState(idSourceSubState,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromDataItemToUIDCall(
			String idSourceState, String idSourceDataItem, String idTargetUIDCall,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromStructureToUIDCall(
			String idSourceState, String idSourceStructure, String idTargetUIDCall,
			String idTransition, String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromDataItemInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromStructureInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			Transition transition = new Transition(idTransition, idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition from Set
	public void insertTransitionFromSetDataItemToUIDCall(String idSourceState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetStructureToUIDCall(String idSourceState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetDataItemInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionFromSetStructureInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			sourceState.insertTransitionFromSetStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	// Transition No Returnable from Set
	public void insertTransitionNoReturnableFromSetDataItemToUIDCall(
			String idSourceState, String idSourceDataItem, String idTargetUIDCall,
			String idTransition, String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetDataItem(idSourceDataItem,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetStructureToUIDCall(
			String idSourceState, String idSourceStructure, String idTargetUIDCall,
			String idTransition, String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetStructure(idSourceStructure,
					transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetDataItemInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceDataItem, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetDataItemInSubState(
					idSourceSubState, idSourceDataItem, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

	public void insertTransitionNoReturnableFromSetStructureInSubStateToUIDCall(
			String idSourceState, String idSourceSubState,
			String idSourceStructure, String idTargetUIDCall, String idTransition,
			String condition, String option, int number) {

		State sourceState = returnState(idSourceState);

		if (sourceState != null) {
			TransitionFromSet transition = new TransitionFromSet(idTransition,
					idTargetUIDCall);
			transition.setCondition(condition);
			transition.setOption(option);
			transition.setNumber(number);
			transition.setNoReturn(true);
			sourceState.insertTransitionFromSetStructureInSubState(
					idSourceSubState, idSourceStructure, transition);

		} else
			throw new UIDException(UIDException.NOT_EXISTING_STATE,
					"There is no state with this id");

	}

}
